﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TryTM
{
    delegate void CreateViewOfCertainFileType_delegate(string WhatFile);
    class ClassUsedExtention //класс для 1 расширения
    {
        string FileExtention;
        public ClassUsedExtention(string FileExtentionUsed, CreateViewOfCertainFileType_delegate CreateViewOfCertainFileTypeDES)
        {
            FileExtention = FileExtentionUsed;
            CreateViewOfCertainFileType = CreateViewOfCertainFileTypeDES;
        }

        public string GetExtention()
        {
            return this.FileExtention;
        }

        public CreateViewOfCertainFileType_delegate CreateViewOfCertainFileType;
    }
    class ClassUsedFileExtentions //класс сразу для всей группы расширений
    {
        List<ClassUsedExtention> UsedExtentionsList;
        public ClassUsedFileExtentions()
        {
            UsedExtentionsList = new List<ClassUsedExtention>();
        }
        public void AddItem(ClassUsedExtention NewItem)
        {
            UsedExtentionsList.Add(NewItem);
        }
        public string GetFilter_ForOpenFileDlg()
        {
            string ResultSTR = "";
            foreach (ClassUsedExtention mi in UsedExtentionsList)
            {
                ResultSTR = ResultSTR+mi.GetExtention() + " документы (*" + mi.GetExtention() + ")|*" + mi.GetExtention() + "|";
            }
            ResultSTR = ResultSTR.Remove(ResultSTR.Length - 1);
            return ResultSTR;
        }
        public bool HasSuchExtention(string WhatExtention)
        {
            return (from ClassUsedExtention mi in UsedExtentionsList
                    where mi.GetExtention() == WhatExtention.ToLower().Trim()
                    select mi).Count() > 0;
        }
        public void CreateViewOfCertainFileType(string WhatExtention, string WhatFile)
        {
            ClassUsedExtention MyCUE = (from ClassUsedExtention mi in UsedExtentionsList
                                          where mi.GetExtention() == WhatExtention.ToLower().Trim()
                                          select mi).ToArray()[0];
            MyCUE.CreateViewOfCertainFileType(WhatFile);
        }
    }
}
